package com.enzoism.springboot.fastjson.controller;

import com.enzoism.springboot.fastjson.dao.ScoresDao;
import com.enzoism.springboot.fastjson.model.Scores;
import com.enzoism.springboot.fastjson.result.RequestResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Controller直接调用dao层代码
 */
@RequestMapping("dao")
@RestController
public class ScoresDaoController {
    @Resource
    public ScoresDao scoresDao;

    /**
     * 列表
     */
    @GetMapping("list")
    public RequestResult selectDataList() {
        List<Scores> scoreList = scoresDao.selectDataList();
        return RequestResult.success(scoreList);
    }

    /**
     * 详情
     */
    @GetMapping("detail/{id}")
    public RequestResult selectByPrimaryKey(@PathVariable Integer id) {
        Scores scores = scoresDao.selectByPrimaryKey(id);
        return RequestResult.success(scores);
    }

    /**
     * 更新
     */
    @PostMapping("update")
    public RequestResult selectByPrimaryKey(@RequestBody Scores scores) {
        // 1-先进行对象更新
        scoresDao.updateByPrimaryKey(scores);
        // 2-进行数据查询返回
        return selectByPrimaryKey(scores.getId());
    }

}
